<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>libjpeg Interoperability</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="index.html" title="libiptcdata Reference Manual">
<link rel="up" href="index.html" title="libiptcdata Reference Manual">
<link rel="prev" href="iptc-overview.html" title="libiptcdata Overview">
<link rel="next" href="iptc-i18n.html" title="Internationalization">
<meta name="generator" content="GTK-Doc V1.10 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="ch01.html" title="IPTC Data Manipulation">
<link rel="chapter" href="ch02.html" title="Format-specific Functions">
<link rel="chapter" href="ch03.html" title="Helper Functions">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="iptc-overview.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td> </td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">libiptcdata Reference Manual</th>
<td><a accesskey="n" href="iptc-i18n.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry" lang="en">
<a name="iptc-libjpeg"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle">libjpeg Interoperability</span></h2>
<p>libjpeg Interoperability — an example of using libiptcdata together with libjpeg</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1" lang="en">
<a name="i18n"></a><h2>Reading IPTC data from a file parsed with libjpeg</h2>
<p>
	 libjpeg is a popular library for parsing jpeg files because
	 it is free, fast, and widely available on many platforms.  It
	 is easy to combine libiptcdata with code that already uses
	 libjpeg to decompress a jpeg file.  The following example shows
	 how to extract IPTC data while a file is being parsed by libjpeg:
	</p>
<pre class="programlisting">
IptcData *d;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * infile;
int ps3_pos = 0, ps3_len;
jpeg_saved_marker_ptr marker;

infile = fopen (path, "r");
if (!infile)
	return -1;

/* decompress the jpeg */
cinfo.err = jpeg_std_error (&amp;jerr);
jpeg_create_decompress (&amp;cinfo);
jpeg_stdio_src (&amp;cinfo, infile);
/* be sure to save the APP13 header, which might contain IPTC data */
jpeg_save_markers (&amp;cinfo, JPEG_APP0+13, 0xffff);
jpeg_read_header (&amp;cinfo, TRUE);

/* look for an IPTC header */
marker = cinfo.marker_list;
while (marker) {
	if (marker-&gt;marker == JPEG_APP0+13) {
		ps3_pos = iptc_jpeg_ps3_find_iptc (marker-&gt;data,
				marker-&gt;data_length, &amp;ps3_len);
		if (ps3_pos &gt; 0)
			break;
	}
	marker = marker-&gt;next;

}

if (!marker) {
	/* clean up if we don't find IPTC data */
	jpeg_destroy_decompress (&amp;cinfo);
	fclose (infile);
	return 0;
}

/* parse the IPTC data */
d = iptc_data_new_from_data (marker-&gt;data + ps3_pos, ps3_len);

/* clean up */
jpeg_destroy_decompress (&amp;cinfo);
fclose (infile);
	</pre>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.10</div>
</body>
</html>
